//用户
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var UserController = (function (_super) {
    __extends(UserController, _super);
    function UserController($scope, $state, userService, rolesService, valueService, $ngBootbox) {
        var _this = this;
        _super.call(this, $scope);
        this.$state = $state;
        this.userService = userService;
        this.rolesService = rolesService;
        this.valueService = valueService;
        this.$ngBootbox = $ngBootbox;
        /**
         * 启用
         */
        this.showEnableUserDialog = function (userId) {
            _this.$ngBootbox.confirm("是否启用？").then(function (e) {
                _this.userService.setAccountLockoutState(userId, false).then(function (result) {
                    _this.query();
                });
            });
        };
        /**
         * 跳转页面（强制修改）
         */
        this.linkToUsersEdit = function () {
            _this.$state.go("app.management.user_edit", { userId: _this.$scope.detail.userId, realName: _this.$scope.detail.userName, roles: _this.$scope.detail.roles });
            $('#myModal').modal('hide');
        };
        this.init();
    }
    UserController.prototype.init = function () {
        var _this = this;
        _super.prototype.init.call(this);
        this.$scope.editUser = function (row) { return _this.showEditUserDialog(row); };
        this.$scope.enableUser = this.showEnableUserDialog;
        this.$scope.disableUser = function (userId) { return _this.showDisableUserDialog(userId); };
        this.$scope.queryTerms = {
            searchingKeyWord: "",
            searchingCarCode: "",
            searchingStartTime: moment("0001-01-01").toDate(),
            searchingEndTime: new Date(),
            searchingRoleId: "",
            searchingState: null,
            useCache: false
        };
        this.$scope.gridOptions = {
            enableSorting: false,
            useExternalPagination: true,
            //useExternalSorting: true,
            enableColumnResizing: true,
            paginationPageSizes: [10, 20, 30],
            columnDefs: [
                { name: "序号", field: "index", enableColumnMenu: false },
                { name: "车牌号", field: "carNumber", enableColumnMenu: false },
                { name: "车型", field: "carType", enableColumnMenu: false },
                { name: "车长", field: "carLength", enableColumnMenu: false },
                { name: "用户名", field: "userName", enableColumnMenu: false },
                { name: "真实姓名", field: "realName", enableColumnMenu: false },
                { name: "实名认证状态", field: "realNameState", enableColumnMenu: false },
                { name: "实名申请时间", field: "certificationTime", enableColumnMenu: false },
                { name: "禁用", field: "isLockedout", enableColumnMenu: false },
                { name: "角色", field: "roles", enableColumnMenu: false },
                {
                    name: "操作",
                    cellFilter: "checkmark",
                    cellTemplate: '<a data-toggle="modal" data-target="#myModal" class="fa fa-edit m-l-xs primary text-info" title="编辑" ng-click="grid.appScope.editUser(row.entity)"></a> <a class="fa fa-check-circle primary text-success" ng-click="grid.appScope.enableUser(row.entity.userId)" title="启用" ng-hide="row.entity.isEnabled"></a> <a class="fa fa-minus-circle primary text-primary" ng-show="row.entity.isEnabled" title="禁用" ng-click="grid.appScope.disableUser(row.entity.userId)"></a>',
                    enableColumnMenu: false
                }
            ],
            onRegisterApi: function (gridApi) {
                _this.gridApi = gridApi;
                gridApi.pagination.on.paginationChanged(_this.$scope, _this.paginationChanged);
            }
        };
        this.query();
        this.loadChekoutStateDropDown();
        this.loadRolesDropDown();
    };
    UserController.prototype.loadData = function (queryTerms, skip, count) {
        var _this = this;
        this.userService.getList(queryTerms.searchingKeyWord, queryTerms.searchingCarCode, queryTerms.searchingStartTime, queryTerms.searchingEndTime, queryTerms.searchingRoleId, queryTerms.searchingState, queryTerms.useCache, skip, count).then(function (result) {
            _this.$scope.gridOptions.totalItems = result.data.total;
            _this.$scope.gridOptions.data = result.data.list;
            if (skip == 0) {
                _this.$scope.gridOptions.paginationCurrentPage = 1;
            }
            _this.$scope.querying = false;
        }, function (error) {
            _this.$scope.querying = false;
        });
    };
    /**
     *加载审核状态
     */
    UserController.prototype.loadChekoutStateDropDown = function () {
        this.$scope.chekoutStateDropDown = this.valueService.getCheckStateList().list;
    };
    /**
     * 加载角色
     */
    UserController.prototype.loadRolesDropDown = function () {
        var _this = this;
        this.rolesService.getList().then(function (result) {
            _this.$scope.rolesDropDown = result.data.list;
        });
    };
    /**
     * 显示实名认证窗口（编辑）
     */
    UserController.prototype.showEditUserDialog = function (user) {
        var _this = this;
        this.$scope.title = "编辑";
        this.userService.getDetail(user.userId).then(function (result) {
            var obj = _this.valueService.getCheckStateList().list;
            _this.$scope.detail = {
                userId: user.userId,
                carCode: result.data.carCode,
                userName: user.realName || user.userName || user.phoneNumber,
                roles: user.roles,
                realHeadImageStatus: _this.valueService.getCheckStateList().list[result.data.realHeadState].text,
                idCardImageSatus: _this.valueService.getCheckStateList().list[result.data.idCardState].text,
                drivingLicenseImageStatus: _this.valueService.getCheckStateList().list[result.data.drivingLicenseState].text,
                vehicleLicenseImageStatus: _this.valueService.getCheckStateList().list[result.data.vehicleLicenseState].text,
                realHeadImage: result.data.realHeadImage || "img/a1.jpg",
                idCardImage: result.data.idCardImage || "img/a1.jpg",
                drivingLicenseImage: result.data.drivingLicenseImage || "img/a1.jpg",
                vehicleLicenseImage: result.data.vehicleLicenseImage || "img/a1.jpg",
                realHeadImageTool: result.data.realHeadState == 2 && result.data.realHeadImage !== null,
                idCardImageTool: result.data.idCardState == 2 && result.data.idCardImage !== null,
                drivingLicenseImageTool: result.data.drivingLicenseState == 2 && result.data.drivingLicenseImage !== null,
                vehicleLicenseImageTool: result.data.vehicleLicenseState == 2 && result.data.vehicleLicenseImage !== null,
                clickOkPassState: true,
                clickRemovePassState: true,
                clickIdCardOkPassState: true,
                clickIdCardRemovePassState: true,
                clickDrivingLicenseOkPassState: true,
                clickDrivingLicenseRemovePassState: true,
                clickVehicleLicenseOkPassState: true,
                clickVehicleLicenseRemovePassState: true,
                drivingLicenseCertificated: result.data.drivingLicenseState,
                realHeadImageCertificated: result.data.realHeadState,
                idCardCertificated: result.data.idCardState,
                vehicleLicenseCertificated: result.data.vehicleLicenseState,
                message: result.data.message,
                click: function () { return _this.editUser(); },
                clickOk: function (statusValue) { return _this.statePassCheck('pass', statusValue, false); },
                clickOkPass: function (statusValue) { return _this.statePassCheck('pass', statusValue, true); },
                clickRemove: function (statusValue) { return _this.statePassCheck('remove', statusValue, null, false); },
                clickRemovePass: function (statusValue) { return _this.statePassCheck('remove', statusValue, null, true); },
                linkToUsersEdit: _this.linkToUsersEdit
            };
        });
    };
    UserController.prototype.editUser = function () {
        var _this = this;
        this.$ngBootbox.confirm("确定保存该数据吗？").then(function (e) {
            _this.userService.putUserRealNameCertificationStatus(_this.$scope.detail.userId, _this.$scope.detail.carCode, _this.$scope.detail.drivingLicenseCertificated, _this.$scope.detail.realHeadImageCertificated, _this.$scope.detail.idCardCertificated, _this.$scope.detail.vehicleLicenseCertificated).then(function (result) {
                _this.query();
                $('#myModal').modal('hide');
            });
        });
    };
    /**
     * 禁用
     */
    UserController.prototype.showDisableUserDialog = function (userId) {
        var _this = this;
        this.$ngBootbox.confirm("是否启用？").then(function (e) {
            _this.userService.setAccountLockoutState(userId, true).then(function (result) {
                _this.query();
            });
        });
    };
    /**
     * 认状态函数
     */
    UserController.prototype.statePassCheck = function (way, statusValue, passValue, dispassValue) {
        if (statusValue == 'RealHeadImage') {
            switch (way) {
                case 'pass':
                    return this.$scope.detail.clickOkPassState = passValue,
                        this.$scope.detail.realHeadImageCertificated = this.getStateResult(this.$scope.detail.clickRemovePassState, this.$scope.detail.clickOkPassState);
                case 'remove':
                    return this.$scope.detail.clickRemovePassState = dispassValue,
                        this.$scope.detail.realHeadImageCertificated = this.getStateResult(this.$scope.detail.clickRemovePassState, this.$scope.detail.clickOkPassState);
            }
        }
        else if (statusValue == 'IDCardImage') {
            switch (way) {
                case 'pass':
                    return this.$scope.detail.clickIdCardOkPassState = passValue,
                        this.$scope.detail.idCardCertificated = this.getStateResult(this.$scope.detail.clickIdCardRemovePassState, this.$scope.detail.clickIdCardOkPassState);
                case 'remove':
                    return this.$scope.detail.clickIdCardRemovePassState = dispassValue,
                        this.$scope.detail.idCardCertificated = this.getStateResult(this.$scope.detail.clickIdCardRemovePassState, this.$scope.detail.clickIdCardOkPassState);
            }
        }
        else if (statusValue == 'DrivingLicenseImage') {
            switch (way) {
                case 'pass':
                    return this.$scope.detail.clickDrivingLicenseOkPassState = passValue,
                        this.$scope.detail.drivingLicenseCertificated = this.getStateResult(this.$scope.detail.clickDrivingLicenseRemovePassState, this.$scope.detail.clickDrivingLicenseOkPassState);
                case 'remove':
                    return this.$scope.detail.clickDrivingLicenseRemovePassState = dispassValue,
                        this.$scope.detail.drivingLicenseCertificated = this.getStateResult(this.$scope.detail.clickDrivingLicenseRemovePassState, this.$scope.detail.clickDrivingLicenseOkPassState);
            }
        }
        else if (statusValue == 'vehicleLicenseImage') {
            switch (way) {
                case 'pass':
                    return this.$scope.detail.clickVehicleLicenseOkPassState = passValue,
                        this.$scope.detail.vehicleLicenseCertificated = this.getStateResult(this.$scope.detail.clickVehicleLicenseRemovePassState, this.$scope.detail.clickVehicleLicenseOkPassState);
                case 'remove':
                    return this.$scope.detail.clickVehicleLicenseRemovePassState = dispassValue,
                        this.$scope.detail.vehicleLicenseCertificated = this.getStateResult(this.$scope.detail.clickVehicleLicenseRemovePassState, this.$scope.detail.clickVehicleLicenseOkPassState);
            }
        }
    };
    /**
     * 实名认证状态转换（提交数据）
     */
    UserController.prototype.getStateResult = function (clickRemovePassState, clickOkPassState) {
        if (clickRemovePassState == true && clickOkPassState == true) {
            return 2;
        }
        else if (clickRemovePassState == false) {
            return 4;
        }
        else if (clickOkPassState == false) {
            return 3;
        }
    };
    ;
    return UserController;
}(ListController));
app.controller('userController', ['$scope', '$state', 'userService', 'rolesService', 'valueService', '$ngBootbox', UserController]);
